package com.situ.mall.controller.back;

import java.util.List;

import org.apache.jasper.tagplugins.jstl.core.If;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.common.ServerResponse;
import com.situ.mall.entity.Order;
import com.situ.mall.entity.OrderItem;
import com.situ.mall.service.IOrderItemService;
import com.situ.mall.service.IOrderService;
import com.situ.mall.service.IUserService;

@Controller
@RequestMapping(value="/order")
public class OrderController {
	@Autowired
	private IOrderService orderService;
	@Autowired
	private IOrderItemService orderItemService;
	@Autowired
	private IUserService userService;
	
	//得到界面
	@RequestMapping(value="/getOrderPage")
	public String getOrderPage(Model model) {
		return "order/order";
	}
	
	
	//商品列表展示分页
	@RequestMapping(value="/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page,Integer limit,Order order) {
		ServerResponse serverResponse = orderService.pageList(page,limit,order);
		
		return serverResponse;
	}
	
	//删除订单
	@RequestMapping(value="/deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id) {
		return orderService.deleteById(id);
	}
	
	/*批量删除订单*/
	@RequestMapping(value="/deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(String ids) {
		return orderService.deleteAll(ids);
	}
	
	//查看子订单内容
	@RequestMapping(value="/getOrderItemPage")
	public String getOrderItemPage(String orderNo,Model model) {
		//转换为long类型
		Long orderNos = Long.parseLong(orderNo);
		List<OrderItem> orderItems = orderItemService.selectOrderItem(orderNos);
		model.addAttribute("orderItems",orderItems);
		return "order/order_item";
	}
}
